package main

func main() {

}

type ListNode struct {
	Val  int
	Next *ListNode
}

/**
 * @Description:给你一个链表的头节点 head ，旋转链表，将链表每个节点向右移动 k 个位置。
 */
func rotateRight(head *ListNode, k int) *ListNode {
	if k == 0 || head == nil || head.Next == nil {
		return head
	}
	resultLen := 0
	temp := head
	for temp != nil {
		resultLen++
		temp = temp.Next
	}

	add := resultLen - k%resultLen
	if add == resultLen {
		return head
	}

	temp = head
	for add > 0 {
		temp = temp.Next
		add--
	}
	result := temp.Next
	temp.Next = nil

	return result
}

/**
 * @Description: 获取链表的长度
 */
func getNodeLen(head *ListNode) int {
	resultLen := 0
	temp := head
	for temp != nil {
		resultLen++
		temp = temp.Next
	}
	return resultLen
}
